***********replication analytic code for estimating effects of paid maternity on infant mortality*****************;
********results provided in "Increased duration of paid maternity leave lowers infant mortality in low- and middle-
income countries: a quasi-experimental study" by Nandi et al., published in PLOS MEDICINE on March 29, 2016*******;
 

*IMPORT DATASET FOR ANALYSIS OF INFANT MORTALITY, NAMED 'INFM_rep_20160601';

libname rep 'X:\'; *insert directory where replication file 'INFM_rep_20160601' is stored;
run;

data infm_rep;
set rep.INFM_rep_20160601;
run;

proc contents data=infm_rep varnum short; run;

proc sort data=infm_rep; by iso3 yearbirth; run;


*WE CONDUCTED A COMPLETE CASE ANALYSIS THAT RESTRICTED ANALYSES TO OBSERVATIONS WITH NONMISSING COVARIATE VALUES;

data infm_rep; 
set infm_rep;
if ftem>. and durm>. and infdeath>. and male>. and edumother>. and wq2-wq5>. and urban>. and bthinval24>. 
and age2039>. and age40>. and brdelpro>.; 
run;


*MAIN ANALYSES (Table 3). The following models correspond to models (1)-(3) in table 3: Effects of an increase in paid 
maternity leave, measured by an additional month of paid leave, on the number of infant deaths per 1000 live births, 
Demographic and Health Surveys, 2000-2007;

*model 1: with fixed effects for country and year;

proc surveyreg data=infm_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model infdeath=durm_lag1 iso3 yearbirth/solution clparm;
weight dnwt; 
run;


*Model 2: Model 1 + measured individual, household, and country-level characteristics;

proc surveyreg data=infm_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model infdeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp /solution clparm;
weight dnwt;
run;


*Model 3: Model 2 + per capita total and government health expenditures--these data were unavailable for all 
years for Zimbabwe and observations from Zimbabwe were therefore dropped from Model 3;

proc surveyreg data=infm_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model infdeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*ANCILLARY ANALYSES;

*Table S2. effect of effect of paid maternity leave on infant morality on the risk ratio scale;

proc genmod data=infm_rep descending order=freq;
class iso3 yearbirth;
model infdeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/link=log dist=poisson;
repeated subject=iso3/type=ind; 
weight dnwt;
run;


*Table S3 and Figure S2. Models examining potential non-linearity in the effect of paid maternity leave on infant morality 
by introducing a quadratic duration of paid leave variable to a fully adjusted model;

proc surveyreg data=infm_rep order=freq;
cluster iso3;
class iso3 yearbirth infdeath;
model infdeath=durm_lag1|durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
store nonlin_inf;
run;

ods graphics on;
proc plm source=nonlin_inf;
effectplot fit (x=durm_lag1);
run;
ods graphics off;


*SENSITIVITY ANALYSES (Table S4). the following models correspond to models (a)-(d) in table S4:

*Model a. measures the effects of an additional month of paid leave in full time equivalent (FTE) units, 
obtained by multiplying the legislated length of leave by the wage replacement rate (therefore this model does 
not additionally control for the wage replacement rate);

proc surveyreg data=infm_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model infdeath=ftem_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*Model b. unweighted estimates;

proc surveyreg data=infm_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model infdeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
run;


*Model c. this model added to our primary exposure, the lagged effect of paid maternity leave (t-1), 
parameters representing paid maternity leave in preceding years (t-3, t-2), the survey year (t), 
and subsequent years (t+1, t+2, t+3); 

proc surveyreg data=infm_rep order=freq;
cluster iso3;
class iso3 yearbirth;
model infdeath=durm_lag3 durm_lag2 durm_lag1 durm durm_lead1 durm_lead2 durm_lead3 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;


*Model d. this model restricted the set of control countries to those with similar trends in infant mortality 
in the decade prior to the study period, as described in the S2 Text;

data infm_rep_matched; 
set infm_rep;
if iso3 in ('ZWE', 'BGD', 'KEN', 'LSO', 'UGA', 'ARM', 'BOL', 'EGY', 'GHA', 'HND', 'MDG', 'TZA');
run;

proc surveyreg data=infm_rep_matched order=freq;
cluster iso3;
class iso3 yearbirth;
model infdeath=durm_lag1 iso3 yearbirth 
male edumother wq2-wq5 urban bthinval24 age2039 age40 brdelpro
wrrw_lag1 logdpcapita lfp lphe lthe/solution clparm;
weight dnwt;
run;









